import time

from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

from Base.BasePage import BasePage


class Online(BasePage):
    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver
        # 理财
        self.licai = (By.XPATH, '//*[@id="mlayout"]/div[1]/div[2]/div/ul/li[3]/a')
        # 在线申请
        self.online_aplay = (By.XPATH, '//*[@id="mlayout"]/div[1]/div[2]/div/ul/li[3]/ul/li[2]/a')
        # 项目名称
        self.name = (By.XPATH, '//*[@id="applyForm"]/div/div[1]/div/input')
        # 所在城市1
        self.select1 = (By.XPATH, '//*[@id="applyForm"]/div/div[2]/div/select[1]')
        # self.select1 = (By.CSS_SELECTOR, 'u-sel.ng-isolate-scope.ng-pristine.ng-valid')
        # '//*[@id="applyForm"]/div/div[2]/div/select[1]'
        self.select2 = (By.XPATH, '//*[@id="applyForm"]/div/div[2]/div/select[2]')
        # 借款金额
        self.brw_money = (By.XPATH, '//*[@id="applyForm"]/div/div[3]/div/input')
        # 借款期限
        self.date = (By.XPATH, '//*[@id="applyForm"]/div/div[4]/div/input')
        # 年汇报率
        self.apr = (By.NAME, "apr")
        # 详细描述
        self.contents = (By.NAME, 'contents')
        # 提交
        self.submit = (By.XPATH, '//*[@id="applyForm"]/div/div[7]/input')


    def oline_apply_money(self):
        """
        点击在线申请
        :return:
        """
        self.move_to_element(self.licai)
        time.sleep(2)
        self.click_element(self.online_aplay)

    def online_apply_input(self, name, value1, value2, brw_money, date, apr, contents):
        """

        :param name: 项目名称
        :param value1: 选择1
        :param value2: 选择2
        :param brw_money: 借款金额
        :param date: 借款时间
        :param apr: 利润
        :param contents:备注
        :return: 无
        """
        self.switch_window(self.name)
        self.base_clear_input(self.name, name)
        time.sleep(1)
        # 下拉框选择
        select = Select(self.get_element(self.select1))
        # select.select_by_value(value1)
        select.select_by_visible_text(value1)
        time.sleep(2)
        Select(self.get_element(self.select2)).select_by_value(value2)
        self.base_clear_input(self.brw_money, brw_money)
        self.base_clear_input(self.date, date)
        self.base_clear_input(self.apr, apr)
        self.base_clear_input(self.contents, contents)
        self.click_element(self.submit)